package com.gml.design.other.singleton;

/**
 * @ClassName : Singleton07
 * @Description : 静态内部类实现单例
 *    JVM保证单例，虚拟机加载class时只加载一次
 *    加载外部类时不会加载静态内部类，这样可以实现懒加载
 * @Author : gml
 * @Date: 2021-04-01 14:37
 */
public class Singleton07 {

    private Singleton07(){}

    public static class Singleton07Holder{
        private final static Singleton07 INSTANCE = new Singleton07();
    }

    public static Singleton07 getInstance(){
        return Singleton07Holder.INSTANCE;
    }

    public static void main(String[] args) {
        for (int i = 0; i < 100; i++) {
            new Thread(()->{
                System.out.println(Singleton07.getInstance().hashCode());
            }).start();
        }
    }

}
